/*
 * @Author       : LuHeQiu
 * @Date         : 2023-04-26 17:35:45
 * @LastEditTime : 2023-04-26 22:33:15
 * @LastEditors  : LuHeQiu
 * @Description  : 
 * @FilePath     : /Inspect/Application/function.c
 * @HomePage     : https://www.luheqiu.com
 */
#include "function.h"
#include "usart.h"

uint8_t main_uart_rx_buff[UART_BUFFERSIZE];
// uint8_t main_uart_tx_buff[UART_BUFFERSIZE];
uint8_t   rf_uart_rx_buff[UART_BUFFERSIZE];
// uint8_t   rf_uart_tx_buff[UART_BUFFERSIZE];

uint16_t main_rx_ptr = 0;
uint16_t main_tx_ptr = 0;
uint16_t rf_rx_ptr = 0;
uint16_t rf_tx_ptr = 0;

void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) {
    if (huart == &MAIN_UART) {
        main_rx_ptr += 1;
        if(main_rx_ptr==UART_BUFFERSIZE){
            main_rx_ptr = 0;
        }
        // HAL_UART_Transmit(&RF_UART, main_uart_rx_buff, UART_BUFFERSIZE,1000);
        HAL_UART_Receive_IT(&MAIN_UART, main_uart_rx_buff + main_rx_ptr, 1);
    } else if (huart == &RF_UART) {
        rf_rx_ptr += 1;
        if(rf_rx_ptr==UART_BUFFERSIZE){
            rf_rx_ptr = 0;
        }
        // HAL_UART_Transmit(&MAIN_UART, rf_uart_rx_buff, UART_BUFFERSIZE,1000);
        HAL_UART_Receive_IT(&RF_UART, rf_uart_rx_buff + rf_rx_ptr, 1);
    }
}

//void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
//{

//    if(huart==&MAIN_UART){
//        for (int i=0;i<Size;i++){
//            rf_uart_tx_buff[i] = main_uart_rx_buff[i];
//        }
//        HAL_UART_Transmit(&RF_UART, rf_uart_tx_buff, Size,1000);
//        //HAL_UART_Transmit_DMA(&RF_UART, main_uart_rx_buff, Size);
//        HAL_UARTEx_ReceiveToIdle_IT(&MAIN_UART,main_uart_rx_buff,UART_BUFFERSIZE);
//  
//    }else if (huart==&RF_UART)
//    {
//        for (int i=0;i<Size;i++){
//            main_uart_tx_buff[i] = rf_uart_rx_buff[i];
//        }
//        HAL_UART_Transmit(&MAIN_UART, main_uart_tx_buff, Size,1000); 
//        //HAL_UART_Transmit_DMA(&MAIN_UART, rf_uart_rx_buff, Size);
//        HAL_UARTEx_ReceiveToIdle_IT(&RF_UART,rf_uart_rx_buff,UART_BUFFERSIZE);
//    }
//    
//}
